﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuKou.Shopspace.Services;
using LuKou.Shopspace.Domains;
using LuKou.Web.BLL.Extensions;

namespace LuKou.Web.BLL.Service
{
    public class ShopArticleService
    {
        private static IShopArticleSvr _svr;
        static ShopArticleService()
        {
            _svr = ServiceHelper.Get<IShopArticleSvr>("IShopArticleSvr");
        }

        public static int GetShopArticleCount(long shopID)
        {
            ShopArticleQueryParam param = new ShopArticleQueryParam();
            param.AddParamOfShopID(shopID);
            return _svr.GetShopArticleCount(param);
        }

        //店铺动态 
        public static PagedList<ShopArticle> GetShopArticleList(int index, int pageSize, long shopID)
        {
            if (index < 1) index = 1;
            if (pageSize < 1) pageSize = 10;
            ShopArticleQueryParam param = new ShopArticleQueryParam();
            param.AddParamOfShopID(shopID);
            param.SetOrderByField(ShopArticleQueryParam.ORDER_ID_DESC);
            List<ShopArticle> result = _svr.GetShopArticleList(param, true, pageSize * (index - 1), pageSize).Cast<ShopArticle>().ToList();
            return new PagedList<ShopArticle>(result, index, pageSize, GetShopArticleCount(shopID));
        }

        public static long AddShopArticle(ShopArticle shopArticle)
        {
            return _svr.AddShopArticle(shopArticle);
        }

        public static void DeleteShopArticle(long id)
        {
            _svr.DeleteShopArticle(id);
        }
    }
}
